package com.wang.utils;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.*;

import java.io.IOException;
import java.io.InputStream;


//sqlSessionFactory   mybatis工具类
public class MybatisUtils {
    //使用mybatis第一步
    //获取sqlSessionFactory对象
    private static SqlSessionFactory sqlSessionFactory;
    static{
        try {
            String resource="mybatis-config.xml";
            InputStream inputStream= Resources.getResourceAsStream(resource);
            sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);

        }catch (IOException e){
        e.printStackTrace();
        }
    }

    //openSession
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }

}
